package vip.rpai.notepad
//ListView适配器
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView

class FruitAdapter(private var context: Context) :
    BaseAdapter() {
    class ViewHolder(view: View) {
        var itemInfoTV: TextView = view.findViewById(R.id.itemInfoTV)
        var itemDateTimeTV: TextView = view.findViewById(R.id.itemDateTimeTV)
    }

    override fun getItem(position: Int): Any = LeSS.dataList[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = LeSS.dataList.size

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val vH: ViewHolder
        val view: View?

        if (convertView == null) {
            view = View.inflate(context, R.layout.main_lv_item, null)
            vH = ViewHolder(view)
            view.tag = vH
        } else {
            view = convertView
            vH = view.tag as ViewHolder
        }
        val item = LeSS.dataList[position]
        vH.itemInfoTV.text = item.info
        vH.itemDateTimeTV.text = item.date
        return view!!
    }
}